@import (once) "../../include/vars";
@import (once) "../../include/mixins";

// Tiles
@tileApp: 44px 44px;
@tileSmall: 70px 70px;
@tileMedium: 150px 150px;
@tileWide: 310px 150px;
@tileLarge: 310px 310px;
@tileMargin: 5px;
@tileCellSize: extract(@tileMedium, 1);
@tileOutlineColor:  rgba(red(@dark), green(@dark), blue(@dark), .1);
@tileTransformPerspective: 500px;
@tileTransformRotate: 0.138372rad;
@tileSize: extract(@tileMedium, 1);

:root {
    --tile-background: #ededed;
    --tile-color: #191919;
    --tile-border-color: var(--border-color);
    --tile-border-radius: 6px;
    --tile-badge-background: rgba(red(@dark), green(@dark), blue(@dark), .1);
    --tile-badge-color: #191919;
    --tile-grid-gap: 10px;
}

.dark-side {
    --tile-background: #26282e;
    --tile-color: #ffffff;
    --tile-border-color: var(--border-color);
    --tile-badge-background: rgba(red(@dark), green(@dark), blue(@dark), .1);
    --tile-badge-color: #ffffff;
}

.tile-small,
.tile-medium,
.tile-wide,
.tile-large,
.tile-app {
    display: block;
    background: var(--tile-background);
    color: var(--tile-color);
    width: extract(@tileMedium, 1);
    height: extract(@tileMedium, 2);
    box-shadow: inset 0 0 1px var(--tile-border-color);
    border-radius: var(--tile-border-radius);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    user-select: none;
    max-width: none!important;
}

.tile {
    &-small {
        width: extract(@tileSmall, 1);
        height: extract(@tileSmall, 2);
    }
    &-medium {
        width: extract(@tileMedium, 1);
        height: extract(@tileMedium, 2);
    }
    &-wide {
        width: extract(@tileWide, 1);
        height: extract(@tileWide, 2);
    }
    &-large {
        width: extract(@tileLarge, 1);
        height: extract(@tileLarge, 2);
    }
    &-app {
        width: extract(@tileApp, 1);
        height: extract(@tileApp, 2);
    }
}

.tile-small,
.tile-medium,
.tile-wide,
.tile-large,
.tile-app {
    .icon {
        max-width: 33%;
        height: 33%;
        position: absolute;
        top: 50%;
        left: 50%;
        .translateY(-50%);
        .translateX(-50%);
        font-size: 50px;
        line-height: 50px;
        z-index: 2;
    }

    .branding-bar {
        height: 32px;
        line-height: 32px;
        position: absolute;
        left: 0;
        bottom: 0;
        right: 0;
        padding: 0 10px 5px;
        font-size: .875rem;
        font-weight: 500;
        .text-ellipsis();
        z-index: 2;
    }

    .badge-top, .badge-bottom {
        position: absolute;
        display: block;
        padding: 4px 8px;
        font-size: 12px;
        text-align: center;
        background-color: @hoverBackground;
        z-index: 2;
    }

    .badge-bottom {
        right: 10px;
        bottom: 0;
    }

    .badge-top {
        top: 10px;
        right: 10px;
    }

    &:hover {
        //outline: @tileOutlineColor solid 4px;
    }
}

.tile {
    &-small {
        .icon {
            max-width: 50%;
            height: 50%;
            font-size: 35px;
            line-height: 35px;
        }
    }
    &-large {
        .icon {
            font-size: 102px;
            line-height: 102px;
        }
    }
    &-app {
        .icon {
            max-width: 75%;
            height: 75%;
        }
    }
}

.tile-small,
.tile-medium,
.tile-wide,
.tile-large,
.tile-app {
    &.transform-right {
        .transformOrigin(left 50%);
        .perspective(@tileTransformPerspective)!important;
        .rotateY(@tileTransformRotate)!important;

        &.tile-small {
            .perspective(@tileTransformPerspective)!important;
            .rotateY(@tileTransformRotate * 2)!important;
        }

        &.tile-wide {
            .perspective(@tileTransformPerspective)!important;
            .rotateY((@tileTransformRotate / 2))!important;
        }

        &.tile-large {
            .perspective(@tileTransformPerspective)!important;
            .rotateY((@tileTransformRotate / 3))!important;
        }
    }

    &.transform-left {
        .transformOrigin(right 50%);
        .perspective(@tileTransformPerspective)!important;
        .rotateY(-@tileTransformRotate)!important;

        &.tile-small {
            .perspective(@tileTransformPerspective)!important;
            .rotateY(-@tileTransformRotate * 2)!important;
        }

        &.tile-wide {
            .perspective(@tileTransformPerspective)!important;
            .rotateY((-@tileTransformRotate / 2))!important;
        }

        &.tile-large {
            .perspective(@tileTransformPerspective)!important;
            .rotateY((-@tileTransformRotate / 3))!important;
        }
    }

    &.transform-top {
        .transformOrigin(50% bottom);
        .perspective(@tileTransformPerspective)!important;
        .rotateX(@tileTransformRotate)!important;

        &.tile-small {
            .perspective(@tileTransformPerspective)!important;
            .rotateX(@tileTransformRotate * 2)!important;
        }

        &.tile-wide {
            .perspective(@tileTransformPerspective)!important;
            .rotateX((@tileTransformRotate / 2))!important;
        }

        &.tile-large {
            .perspective(@tileTransformPerspective)!important;
            .rotateX((@tileTransformRotate / 3))!important;
        }
    }

    &.transform-bottom {
        .transformOrigin(50% top);
        .perspective(@tileTransformPerspective)!important;
        .rotateX(-@tileTransformRotate)!important;

        &.tile-small {
            .perspective(@tileTransformPerspective)!important;
            .rotateX(-@tileTransformRotate * 2)!important;
        }

        &.tile-wide {
            .perspective(@tileTransformPerspective)!important;
            .rotateX((-@tileTransformRotate / 2))!important;
        }

        &.tile-large {
            .perspective(@tileTransformPerspective)!important;
            .rotateX((-@tileTransformRotate / 3))!important;
        }
    }
}


.tiles-grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fit, 70px);
    grid-template-rows: repeat(auto-fit, 70px);
    grid-gap: var(--tile-grid-gap);

    .tile-small {
        grid-column: span 1;
        grid-row: span 1;
    }

    .tile-medium {
        grid-column: span 2;
        grid-row: span 2;
    }

    .tile-wide {
        grid-column: span 4;
        grid-row: span 2;
    }

    .tile-large {
        grid-column: span 4;
        grid-row: span 4;
    }
}

.tiles-grid {
    .create-tiles-cells(@i: 1, @k: 1) when (@k <= @i) {

        .tile-small.col-@{k} {
            grid-column: @k / span 1;
        }

        .tile-medium.col-@{k} {
            grid-column: @k / span 2;
        }

        .tile-wide.col-@{k} {
            grid-column: @k / span 4;
        }

        .tile-large.col-@{k} {
            grid-column: @k / span 4;
        }

        .tile-small.row-@{k} {
            grid-row: @k / span 1;
        }

        .tile-medium.row-@{k} {
            grid-row: @k / span 2;
        }

        .tile-wide.row-@{k} {
            grid-row: @k / span 4;
        }

        .tile-large.row-@{k} {
            grid-row: @k / span 4;
        }

        .create-tiles-cells(@i; @k + 1);
    }
    .create-tiles-cells(12);
}

.tiles-grid {
    &.size-half {
        width: 70px + @tileMargin * 2;
    }

    .create-tiles-grid-size(@i: 1, @k: 1) when (@k <= @i) {
        &.size-@{k} {
            width: (@tileCellSize + @tileMargin * 2) * @k;
        }

        .create-tiles-grid-size(@i; @k + 1);
    }
    .create-tiles-grid-size(12);
}

.tiles-grid {
    each(@mediaBreakpointListMobile, .(@m) {
        @media screen and (min-width: @@m) {
            each(range(12), .(@k) {
                .col-@{m}-@{k} {
                    grid-column: @k;
                }
                .row-@{m}-@{k} {
                    grid-row: @k;
                }
            })
            each(range(12), .(@k) {
                &.size-@{m}-half {
                    width: 70px + @tileMargin * 2;
                }
                &.size-@{m}-@{k} {
                    width: (@tileCellSize + @tileMargin * 2) * @k;
                }
            })
        }
    })
}

.tiles-group {

    width: auto;
    float: left;
    overflow: visible;

    &::before {
        content: attr(data-group-title);
        display: block;
        position: absolute;
        left: 0;
        top: -36px;
        height: 1.5em;
        line-height: 1.5em;
        z-index: 1;
        color: inherit;
    }
}

// Tiles effects
[class*=tile-] {
    &.image-set {
        .img {
            width: 25%;
            height: 50%;
            display: block;
            float: left;
            border: 1px solid @dark;
            background-size: cover;

            &:nth-child(1) {
                width: 50%;
                height: 100%;
            }
        }

        background-size: contain;
        background-position: center;
    }

    .slide {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        display: block;
    }

    [class*=slide-] {
        width: 100%;
        height: 100%;
        position: absolute;
        transition: @transition-base;
    }

    .slide-front {
        top: 0;
        left: 0;
    }

    &.effect-hover-slide-up, &.effect-hover-zoom-up {

        .slide-back {
            top: 100%;
            left: 0;
        }

        &:hover {
            .slide-front {
                .translateY(-100%);
            }
            .slide-back {
                top: 0;
            }
        }
    }

    &.effect-hover-slide-down, &.effect-hover-zoom-down {
        .slide-back {
            top: 0;
            left: 0;
            .translateY(-100%);
        }

        &:hover {
            .slide-front {
                top: 100%;
            }
            .slide-back {
                .translateY(0);
            }
        }
    }

    &.effect-hover-slide-left, &.effect-hover-zoom-left {
        .slide-back {
            top: 0;
            left: 100%;
        }

        &:hover {
            .slide-front {
                .translateX(-100%);
            }
            .slide-back {
                left: 0;
            }
        }
    }

    &.effect-hover-slide-right, &.effect-hover-zoom-right {
        .slide-back {
            top: 0;
            left: 0;
            .translateX(-100%);
        }

        &:hover {
            .slide-front {
                left: 100%;
            }
            .slide-back {
                .translateX(0);
            }
        }
    }

    &.effect-hover-zoom-up, &.effect-hover-zoom-down, &.effect-hover-zoom-left, &.effect-hover-zoom-right {
        &:hover {
            .slide-front {
                left: 0;
                top: 0;
                .scale(2);
            }
        }
    }
}

